#include <input_manager.h>
#include <tslib.h>
#include <stdio.h>
#include <input_manager.h>

static struct tsdev *g_ts;

static int DeviceInit_TouchScreenDev()
{
	g_ts = ts_setup(NULL, 0);
	if (!g_ts)
	{
		printf("ts_setup err\n");
		return -1;
	}

	return 0;
}

static int GetInputEvent_TouchScreenDev(PInputEvent ptInputEvent)
{
	struct ts_sample samp;
	int ret;
	
	ret = ts_read(g_ts, &samp, 1);
	
	if (ret != 1)
		return -1;

	ptInputEvent->iType			= INPUT_TYPE_TOUCH;
	ptInputEvent->iX 			= samp.x;
	ptInputEvent->iY 			= samp.y;
	ptInputEvent->iPressure 	= samp.pressure;
	ptInputEvent->tTime 		= samp.tv;

	return 0;
}

static int DeviceExit_TouchScreenDev()
{
	ts_close(g_ts);
	return 0;
}
static InputDevice g_tTouchScreenDev = {
	.name				="touchScreen",
	.GetInputEvent		=GetInputEvent_TouchScreenDev,
	.DeviceInit			=DeviceInit_TouchScreenDev,
	.DeviceExit			=DeviceExit_TouchScreenDev,
};

void TouchScreenDev_Register(void)
{
	Register_InputDevice(&g_tTouchScreenDev);
}

